import { ActivatedRoute, Params } from '@angular/router';
import { WorkflowStatus } from '../module/workflow-status';
import { ProcessInfo,parame } from './../module/process-info';
import { Injectable } from '@angular/core';
import { Headers, Http, Response } from '@angular/http';
import { Observable } from 'rxjs';
import 'rxjs/add/operator/toPromise';


/**
 * 对workflow提供相关服务
 * 
 * @export
 * @class ProcessInfoService
 */
@Injectable()
export class ProcessInfoService {
    private _status:WorkflowStatus;
    /**
     * 设置请求报头
     * 
     * @private
     * 
     * @memberOf ProcessInfoService
     */
    private headers = new Headers({ 'Content-Type': 'application/json' });

    /**
     * Creates an instance of ProcessInfoService.
     * 
     * @param {Http} http
     * 
     * @memberOf ProcessInfoService
     */
    constructor(private http: Http,private route:ActivatedRoute) { }

    /**
     * 
     * 
     * @param {string} url请求参数
     * @returns {Promise<ProcessInfo>}
     * 
     * @memberOf ProcessInfoService
     */
    getProcessInfo(url:string): Promise<ProcessInfo> {
        return this.http.get(url)
            .toPromise()
            .then(response => response.json().data as ProcessInfo)
            .catch(this.handleError);
    }

    /**
     * 
     * 
     * @private
     * @param {*} error
     * @returns {Promise<any>}
     * 
     * @memberOf ProcessInfoService
     */
    private handleError(error: any): Promise<any> {
        console.log('An error occurred', error); // for demo purposes only
        return Promise.reject(error.message || error);
    }
}